package DataManager;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DataManager {
	
	static DataManager gGobalInstance;
	static public int ORDER_TYPE = 0;
	static public int ORDER_TYPE_FOOD = ORDER_TYPE +1;
	static public int ORDER_TYPE_DISH = ORDER_TYPE +2;
	static public int ORDER_TYPE_DRINKS = ORDER_TYPE +3;
	
	ArrayList< OrderInfo> mOrerInfoList;
	private DataManager(){
	}
	
	public static DataManager getInstance() {
		if (gGobalInstance != null)
			return gGobalInstance;
		
		gGobalInstance = new DataManager();
		return gGobalInstance;
	}
	
	public void init(){
		mOrerInfoList = new ArrayList< OrderInfo>();
	}
	
	public ArrayList< MenuInfo> getAllDiscountList(){
		return null;
	}
	
	public ArrayList< MenuInfo>getAllList(int type){
		ArrayList<MenuInfo> list = new ArrayList<MenuInfo>();
		for(int i = 0; i<=9; i++){
			MenuInfo menu = new MenuInfo(DataManager.ORDER_TYPE_FOOD);
			menu.setId(i);
			menu.setName("FOOD " + 'A' +i);
			menu.setPrice(i+10);
			list.add(menu);
		}
		
		return list;
	}
	
	public void addOrderInfo(int id, String name){
		ArrayList<OrderInfo> list = mOrerInfoList;
		for (Iterator<OrderInfo> i = list.iterator(); i.hasNext();){
			OrderInfo info = i.next();
			if(info.getId() == id){
				info.addCount();
				return;
			}
		}
		
		OrderInfo info = new OrderInfo(id,name);
		info.addCount();
		list.add(info);
	}
	
	public int getOrderCount(int id){
		ArrayList<OrderInfo> list = mOrerInfoList;
		for (Iterator<OrderInfo> i = list.iterator(); i.hasNext();){
			OrderInfo info = i.next();
			if(info.getId() == id){
				return info.getCout();
			}
		}
		return -1;
	}
	
	public ArrayList< OrderInfo> getOrderList(){
		
		return mOrerInfoList;
	}
	
	public void submitOrderInfo(ArrayList< OrderInfo> info){
		
	}
	
	public void getUserInfo(UserInfo info){
		
	}
	
	public MenuInfo getMenuInfo(int id){
		return null;
	}
}
